//
//  HomeRequest.m
//  CreditHub
//
//  Created by xinhualong on 2024/9/12.
//

#import "HomeRequest.h"
#import "UUID.h"
#import "CHLocationManager.h"
#import <sys/utsname.h>

@implementation HomeRequest

// home
+ (void)requestHomeSuccess:(SuccessBlock)successBlock
                   failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpGet:@"/proud/pity" parameters:@{} success:successBlock failure:failereBlock];
    
}
// city List
+ (void)requestCityListSuccess:(SuccessBlock)successBlock
                       failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpGet:@"/proud/garden" parameters:@{} success:^(NSURLSessionDataTask *task, id response) {
        if([response[@"ofexcitement"] integerValue] == 0){
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setObject:response[@"pity"] forKey:@"CityListKey"];
            [defaults synchronize];
        }
        successBlock(task,response);
    } failure:failereBlock];
    
}
// LoadDetails
+ (void)requestLoadDetailseId:(NSString *)lightat
                      success:(SuccessBlock)successBlock
                      failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpPost:@"/proud/asleep" parameters:@{@"lightat":CHString(lightat)} success:successBlock failure:failereBlock];
    
}
//Voucher
+ (void)requestVoucherInfoSuccess:(SuccessBlock)successBlock
                          failure:(FailureBlock)failereBlock{
    [BaseService requestForHttpPost:@"/proud/niceies" parameters:@{} success:successBlock failure:failereBlock];
}
+ (void)requestSaveVoucherPity:(NSString *)pity
                       success:(SuccessBlock)successBlock
                       failure:(FailureBlock)failereBlock{
    [BaseService requestForHttpPost:@"/proud/meetjy" parameters:@{@"pity":CHString(pity)} success:successBlock failure:failereBlock];
}
//Place an order
+ (void)requestPlaceOrderId:(NSString *)orderNo
                     amount:(NSString *)amount
                  limitDate:(NSString *)limitDate
                       type:(NSString *)type
                    success:(SuccessBlock)successBlock
                    failure:(FailureBlock)failereBlock{
    
    NSDictionary *params = @{@"astounded":CHString(orderNo),@"guess":amount,@"behind":limitDate,@"left":type};
    [BaseService requestForHttpPost:@"/proud/upstairs" parameters:params success:successBlock failure:failereBlock];
    
}
// cardDetails
+ (void)requestCardInfoId:(NSString *)lightat
                  success:(SuccessBlock)successBlock
                  failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpPost:@"/proud/shall" parameters:@{@"lightat":CHString(lightat)} success:successBlock failure:failereBlock];
    
}

//
+ (void)requestUploadImage:(UIImage *)image
                   spindly:(NSString *)spindly
                   awfully:(NSInteger)awfully
                   success:(SuccessBlock)successBlock
                   failure:(FailureBlock)failereBlock{
    
    NSData *imageData = [[ImageLoader sharedInstance] compressImage:image toLessThanSize:1000 * 1024];
    
    
    [BaseService postImageWithUrlString:@"/proud/bottom" parameters:@{@"spindly":spindly,@"awfully":@(awfully)} imageData:imageData progress:^(NSProgress *progress) {
        
    } success:successBlock failure:failereBlock];
    
}
// cardDetails
+ (void)requestSaveCardInfo:(NSDictionary *)params
                    success:(SuccessBlock)successBlock
                    failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpPost:@"/proud/flung" parameters:params success:successBlock failure:failereBlock];
    
}
// Personal Info
+ (void)requestCerPersonalInfoId:(NSString *)lightat
                            type:(NSInteger)type
                         success:(SuccessBlock)successBlock
                         failure:(FailureBlock)failereBlock{
    NSString *url = @"";
    if(type == 1){
        url = @"/proud/heundressed";
    }else if(type == 2){
        url = @"/proud/jabbered";
    }else if(type == 3){
        url = @"/proud/bed";
    }
    [BaseService requestForHttpPost:url parameters:@{@"lightat":CHString(lightat)} success:successBlock failure:failereBlock];
    
}
+ (void)requestSaveCerPersonalInfoId:(NSDictionary  *)params
                                type:(NSInteger)type
                             success:(SuccessBlock)successBlock
                             failure:(FailureBlock)failereBlock{
    NSString *url = @"";
    if(type == 1){
        url = @"/proud/comforted";
    }else if(type == 2){
        url = @"/proud/mean";
    }else if(type == 3){
        url = @"/proud/sleep";
    }
    [BaseService requestForHttpPost:url parameters:params success:successBlock failure:failereBlock];
    
}
// contacts information
+ (void)requestCerContactslInfoId:(NSString *)lightat
                          success:(SuccessBlock)successBlock
                          failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpPost:@"/proud/withme" parameters:@{@"lightat":CHString(lightat)} success:successBlock failure:failereBlock];
    
}
+ (void)requestSaveCerContactslInfoId:(NSString *)lightat
                                 pity:(NSString *)pity
                              success:(SuccessBlock)successBlock
                              failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpPost:@"/proud/cuddle" parameters:@{@"lightat":CHString(lightat),@"pity":pity} success:successBlock failure:failereBlock];
    
}
// AddressBook
+ (void)requestSaveAddressBookPity:(NSString *)pity
                           success:(SuccessBlock)successBlock
                           failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpPost:@"/proud/report" parameters:@{@"pity":pity} success:successBlock failure:failereBlock];
    
}

// center
+ (void)requestPersonalCenterSuccess:(SuccessBlock)successBlock
                             failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpGet:@"/proud/disgusted" parameters:@{} success:successBlock failure:failereBlock];
    
}
+ (void)requestHomeCanpinLightat:(NSString *)lightat
                         success:(SuccessBlock)successBlock
                         failure:(FailureBlock)failereBlock{
    
    NSMutableDictionary *dicParams = [NSMutableDictionary dictionary];
    [dicParams setValue:lightat forKey:@"lightat"];
    
    [BaseService requestForHttpPost:@"/proud/which" parameters:dicParams success:successBlock failure:failereBlock];
    
}
+ (void)requestPersonalLogoutSuccess:(SuccessBlock)successBlock
                             failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpGet:@"/proud/shared" parameters:@{} success:successBlock failure:failereBlock];
    
}

+ (void)requestAccountCancellationSuccess:(SuccessBlock)successBlock
                           failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpPost:@"/proud/bettergo" parameters:@{} success:successBlock failure:failereBlock];
    
}


// upload info
+ (void)requestUploadLocation:(NSDictionary *)dicLocation
                      success:(SuccessBlock)successBlock
                   failure:(FailureBlock)failereBlock{
    
    [BaseService requestForHttpPost:@"/proud/despised" parameters:dicLocation success:successBlock failure:failereBlock];
    
}

+ (void)requestUploadGoogleMarketSuccess:(SuccessBlock)successBlock
                   failure:(FailureBlock)failereBlock{
    
    NSMutableDictionary *dicParams = [NSMutableDictionary dictionary];
    [dicParams setValue:[BaseService getIDFA] forKey:@"wasgeorge"];
    [dicParams setValue:[UUID getUUID] forKey:@"red"];
    
    [BaseService requestForHttpPost:@"/proud/gosh" parameters:dicParams success:successBlock failure:failereBlock];
    
}
+ (void)requestUploadPointType:(NSString *)type
                       orderNo:(NSString *)orderNo
                     startTime:(NSString *)startTime
                       endTime:(NSString *)endTime
                       success:(SuccessBlock)successBlock
                       failure:(FailureBlock)failereBlock{
    
    [[CHLocationManager sharedInstance] startUpdatingLocation];
    [CHLocationManager sharedInstance].locationBlock = ^(NSInteger code, CLLocation * _Nonnull currentLocation) {
        
    };
    
    NSMutableDictionary *dicParams = [NSMutableDictionary dictionary];
    [dicParams setValue:type forKey:@"crossly"];
    [dicParams setValue:@"2" forKey:@"finger"];
    [dicParams setValue:startTime forKey:@"received"];
    [dicParams setValue:endTime forKey:@"answer"];
    [dicParams setValue:CHStringIsEmpty(orderNo)?@"":orderNo forKey:@"beforea"];
    [dicParams setValue:[BaseService getIDFA] forKey:@"ahard"];
    [dicParams setValue:[UUID getUUID] forKey:@"poke"];
    [dicParams setValue:[NSString stringWithFormat:@"%.6f",[CHLocationManager sharedInstance].currentLocation.coordinate.longitude] forKey:@"secret"];
    [dicParams setValue:[NSString stringWithFormat:@"%.6f",[CHLocationManager sharedInstance].currentLocation.coordinate.latitude] forKey:@"work"];
   
    [BaseService requestForHttpPost:@"/proud/worm" parameters:dicParams success:successBlock failure:failereBlock];
    
}
+ (void)requestUploadPagePointType:(NSString *)type
                           lightat:(NSString *)lightat{
   
    
    NSMutableDictionary *dicParams = [NSMutableDictionary dictionary];
    [dicParams setValue:type forKey:@"crossly"];
    [dicParams setValue:lightat forKey:@"lightat"];

   
    [BaseService requestForHttpPost:@"/proud/sincerity2" parameters:dicParams success:^(NSURLSessionDataTask *task, id response) {
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}
+ (void)requestUploadDeviceSuccess:(SuccessBlock)successBlock
                   failure:(FailureBlock)failereBlock{
    
    NSMutableDictionary *dicParams = [NSMutableDictionary dictionary];
    // surprise
    NSMutableDictionary *dicSurprise = [NSMutableDictionary dictionary];
    [dicSurprise setObject:[JKMVKeyChainUUID getKeYongCiPan] forKey:@"tower"];
    [dicSurprise setObject:[JKMVKeyChainUUID getZongCiPan] forKey:@"andwent"];
    [dicSurprise setObject:[JKMVKeyChainUUID getZongNeiCunDaXiao] forKey:@"window"];
    [dicSurprise setObject:[JKMVKeyChainUUID getKeYongNeiCunDaXiao] forKey:@"through"];
    
    [dicParams setObject:dicSurprise forKey:@"surprise"];
    
    //battery
    NSMutableDictionary *dicBattery = [NSMutableDictionary dictionary];
    UIDevice *device = [UIDevice currentDevice];
    device.batteryMonitoringEnabled = YES;
    CGFloat batteryLevel = device.batteryLevel*100;
    [dicBattery setObject:[NSString stringWithFormat:@"%d",(int)batteryLevel] forKey:@"interview"];
    UIDeviceBatteryState batteryState = device.batteryState;
    if (batteryState == UIDeviceBatteryStateCharging || batteryState == UIDeviceBatteryStateFull) {
          [dicBattery setObject:@(1) forKey:@"hiswork"];
    }  else {
        [dicBattery setObject:@(0) forKey:@"hiswork"];
    }
    [dicParams setObject:dicBattery forKey:@"peered"];
    
    //messed
    NSMutableDictionary *dicMessed = [NSMutableDictionary dictionary];
    [dicMessed setObject:[BaseService friendlyDeviceName] forKey:@"middle"];
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *machine = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    [dicMessed setObject:machine forKey:@"awfullycross"];
    [dicMessed setObject:[[UIDevice currentDevice] systemVersion] forKey:@"biggest"];
    
    [dicParams setObject:dicMessed forKey:@"messed"];
    
    //dad
    [dicParams setObject:@{@"reporters":[BaseService isSimulator]?@"1":@"0",@"ago":@"0"} forKey:@"dad"];
    
    // inventions
    NSMutableDictionary *dicInventions = [NSMutableDictionary dictionary];
    [dicInventions setObject:[BaseService getIDFA] forKey:@"wasgeorge"];
    [dicInventions setObject:[UUID getUUID] forKey:@"red"];
    
    NSString *languageCode = [[NSLocale preferredLanguages] firstObject];
    [dicInventions setObject:languageCode forKey:@"soundly"];
    [dicInventions setObject:[BaseService checkNetworkPermission] forKey:@"swelled"];
    [dicInventions setObject:[[NSTimeZone systemTimeZone] abbreviation] forKey:@"pride"];
    
    [dicParams setObject:dicInventions forKey:@"inventions"];
    
    //brain
    NSMutableDictionary *dicBrain = [NSMutableDictionary dictionary];
    if(!CHStringIsEmpty([JKMVKeyChainUUID getPhoneConnectWifiAddress])){
        NSDictionary *dic = @{@"amost":[JKMVKeyChainUUID getPhoneConnectWifiAddress],@"wouldwonder":[JKMVKeyChainUUID getPhoneConnectWifiName]};
        [dicBrain setObject:dic forKey:@"unusual"];
    }
    [dicParams setObject:dicBrain forKey:@"brain"];
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dicParams options:0 error:&error];
    NSString *jsonString = @"";
    if (jsonData) {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
       
    }
    [BaseService requestForHttpPost:@"/proud/asif" parameters:@{@"pity":jsonString} success:successBlock failure:failereBlock];
    
}

@end
